package cn.tedu.banner.management.controller;


import cn.tedu.banner.management.pojo.param.BannerAddNewParam;
import cn.tedu.banner.management.pojo.param.BannerParam;
import cn.tedu.banner.management.service.IBannerService;
import cn.tedu.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "1.轮播图管理")
@RestController
@RequestMapping("/banners/")
public class BannerController {
    @Autowired
    private IBannerService bannerService;

    @PostMapping("{sort}/avatar")
    public JsonResult avatar(@PathVariable Integer sort, BannerAddNewParam bannerAddNewParam){
        bannerService.avatar(sort,bannerAddNewParam);
        return JsonResult.ok();
    }

    //添加轮播图
    @PostMapping("add-new")
    @ApiOperation(value = "添加轮播图")
    public JsonResult addNew(BannerParam bannerParam) {
        bannerService.addNew(bannerParam);
        return JsonResult.ok();
    }

    //删除轮播图
    @PostMapping("{id}/delete")
    @ApiOperation(value = "删除轮播图")
    public JsonResult delete(@PathVariable Long id) {
        bannerService.delete(id);
        return JsonResult.ok();
    }

    //用户首页轮播图展示
    @GetMapping("")
    @ApiOperation(value = "用户展示轮播图")
    public JsonResult listForIndex() {
        return JsonResult.ok(bannerService.listForIndex());
    }

    //管理员轮播图列表
    @GetMapping("adminList")
    @ApiOperation(value = "管理员轮播图列表")
    public JsonResult listForAdmin() {
        return JsonResult.ok(bannerService.listForAdmin());
    }
}
